package com.retail.product.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.retail.common.log.annotation.Log;
import com.retail.common.log.enums.BusinessType;
import com.retail.common.security.annotation.RequiresPermissions;
import com.retail.product.common.domain.TSku;
import com.retail.product.service.ITSkuService;
import com.retail.common.core.web.controller.BaseController;
import com.retail.common.core.domain.Result;
import com.retail.common.core.utils.poi.ExcelUtil;
import com.retail.common.core.web.page.TableDataInfo;

/**
 * sku商品套餐 例：苹果14 幻影紫 16+128GController
 * 
 * @author retail
 * @date 2024-02-27
 */
@RestController
@RequestMapping("/sku")
public class TSkuController extends BaseController
{
    @Autowired
    private ITSkuService tSkuService;

    /**
     * 查询sku商品套餐 例：苹果14 幻影紫 16+128G列表
     */
    @RequiresPermissions("product:sku:list")
    @GetMapping("/list")
    public TableDataInfo list(TSku tSku)
    {
        startPage();
        List<TSku> list = tSkuService.selectTSkuList(tSku);
        return getDataTable(list);
    }

    /**
     * 导出sku商品套餐 例：苹果14 幻影紫 16+128G列表
     */
    @RequiresPermissions("product:sku:export")
    @Log(title = "sku商品套餐 例：苹果14 幻影紫 16+128G", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSku tSku)
    {
        List<TSku> list = tSkuService.selectTSkuList(tSku);
        ExcelUtil<TSku> util = new ExcelUtil<TSku>(TSku.class);
        util.exportExcel(response, list, "sku商品套餐 例：苹果14 幻影紫 16+128G数据");
    }

    /**
     * 获取sku商品套餐 例：苹果14 幻影紫 16+128G详细信息
     */
    @RequiresPermissions("product:sku:query")
    @GetMapping(value = "/{skuId}")
    public Result getInfo(@PathVariable("skuId") Integer skuId)
    {
        return success(tSkuService.selectTSkuBySkuId(skuId));
    }

    /**
     * 新增sku商品套餐 例：苹果14 幻影紫 16+128G
     */
    @RequiresPermissions("product:sku:add")
    @Log(title = "sku商品套餐 例：苹果14 幻影紫 16+128G", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody TSku tSku)
    {
        return toAjax(tSkuService.insertTSku(tSku));
    }

    /**
     * 修改sku商品套餐 例：苹果14 幻影紫 16+128G
     */
    @RequiresPermissions("product:sku:edit")
    @Log(title = "sku商品套餐 例：苹果14 幻影紫 16+128G", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody TSku tSku)
    {
        return toAjax(tSkuService.updateTSku(tSku));
    }

    /**
     * 删除sku商品套餐 例：苹果14 幻影紫 16+128G
     */
    @RequiresPermissions("product:sku:remove")
    @Log(title = "sku商品套餐 例：苹果14 幻影紫 16+128G", businessType = BusinessType.DELETE)
	@DeleteMapping("/{skuIds}")
    public Result remove(@PathVariable Integer[] skuIds)
    {
        return toAjax(tSkuService.deleteTSkuBySkuIds(skuIds));
    }

    //@RequiresPermissions("product:sku:findByProductId")
    @Log(title = "查询商品的sku数据")
    @GetMapping("/findByProductId")
    public Result findByProductId(@RequestParam("productId") Integer productId){
        return tSkuService.findByProductId(productId);
    }

    @PostMapping("/orderSkuUpdNumber")
    public Result orderSkuUpdNumber(@RequestParam("str")String str,@RequestParam("number")String number){
        tSkuService.orderSkuUpdNumber(str,number);
        return Result.success ();
    }






















}
